﻿<div [@routerTransition]>
    <div class="m-subheader">
        <div class="row align-items-center">
            <div class="mr-auto col-auto">
                <h3 class="m-subheader__title m-subheader__title--separator">
                    <span>编码库</span>
                </h3>
            </div>
            <div class="col text-right mt-3 mt-md-0">
                <!--
                <div class="btn-group dropdown mr-2" dropdown>
                    <button dropdownToggle class="dropdown-toggle btn btn-outline-success">
                        <i class="far fa-file-excel"></i><span class="caret"></span> {{"ExcelOperations" | localize}}
                    </button>
                    <ul class="dropdown-menu dropdown-menu-right dropdown-excel-operations" *dropdownMenu>
                        < !--<li>
                            <a href="javascript:;"
                               (click)="exportToExcel()">
                                <i class="fa fa-download"></i>
                                {{'ExportToExcel' | localize}}
                            </a>
                        </li>-- >
                        <li>
                            <a href="javascript:;" *ngIf="isGranted('Pages.StandardPartsManager.CodeBase.Add')" class="no-padding">
                                <span>
                                    <p-fileUpload customUpload="true"
                                                  name="ExcelFileUpload"
                                                  #ExcelFileUpload
                                                  maxFileSize="10000000"
                                                  auto="auto"
                                                  accept=".csv,.xls,.xlsx"
                                                  (uploadHandler)="uploadExcel($event)"
                                                  (onError)="onUploadExcelError()"
                                                  chooseLabel="批量导入">
                                    </p-fileUpload>
                                </span>
                            </a>
                        </li>
                        <li class="dropdown-divider"></li>
                        <li>
                            <span class="dropdown-item-text text-muted" href="#">
                                <a href="./assets/sampleFiles/CodeBase.xlsx">下载模板</a>
                            </span>
                        </li>
                    </ul>
                </div>-->
                <button (click)="createDetail()" *ngIf="isGranted('Pages.StandardPartsManager.CodeBase.Add')" class="btn btn-primary"><i class="fa fa-plus"></i>添加编码库</button>                
            </div>
        </div>
    </div>
    <div class="m-content">
        <div class="m-portlet m-portlet--mobile">
            <div class="m-portlet__body">
                <form class="horizontal-form" autocomplete="off">
                    <div class="m-form m-form--label-align-right">
                        <div class="row align-items-center m--margin-bottom-10">
                            <div class="col-xl-12">
                                <div class="form-group m-form__group align-items-center">
                                    <div class="input-group">
                                        <input [(ngModel)]="filterText" name="filterText" autoFocus class="form-control m-input" [placeholder]="l('SearchWithThreeDot')" type="text">
                                        <span class="input-group-btn">
                                            <button (click)="getCodeBase()" class="btn btn-primary" type="submit"><i class="flaticon-search-1" [attr.aria-label]="l('Search')"></i></button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>

                <div class="row align-items-center">
                    <!--<Primeng-TurboTable-Start>-->
                    <div class="primeng-datatable-container"
                         [busyIf]="primengTableHelper.isLoading">
                        <p-table #dataTable
                                 (onLazyLoad)="getCodeBase($event)"
                                 [value]="primengTableHelper.records"
                                 rows="{{primengTableHelper.defaultRecordsCountPerPage}}"
                                 [paginator]="false"
                                 [lazy]="true"
                                 [scrollable]="true"
                                 ScrollWidth="100%"
                                 [responsive]="primengTableHelper.isResponsive"
                                 [resizableColumns]="primengTableHelper.resizableColumns">
                            <ng-template pTemplate="header">
                                <tr>
                                    <th style="width: 100px" [hidden]="!isGrantedAny('Pages.StandardPartsManager.CodeBase.Add', 'Pages.StandardPartsManager.CodeBase.Edit', 'Pages.StandardPartsManager.CodeBase.Delete')">{{'Actions' | localize}}</th>
                                    <th style="width: 50px;text-align: center;">
                                        序号
                                    </th>
                                    <th style="width: 100px;text-align: center;" pSortableColumn="serialNumber">
                                        编码
                                        <p-sortIcon field="id"></p-sortIcon>
                                    </th>
                                    <th style="width: 100px;text-align: center;"  pSortableColumn="features.displayName">
                                        名称
                                        <p-sortIcon field="features.displayName"></p-sortIcon>
                                    </th>
                                    <th style="width: 100px;text-align: center;"  pSortableColumn="standardType">
                                        分类
                                        <p-sortIcon field="standardType"></p-sortIcon>
                                    </th>
                                    <th style="width: 100px;text-align: center;"  pSortableColumn="features.standardNumber">
                                        标准
                                        <p-sortIcon field="features.standardNumber"></p-sortIcon>
                                    </th>
                                    <th style="width: 100px;text-align: center;"  pSortableColumn="features.specification">
                                        规格
                                        <p-sortIcon field="features.specification"></p-sortIcon>
                                    </th>
                                    <th style="width: 100px;text-align: center;" pSortableColumn="features.materials">
                                        材料
                                        <p-sortIcon field="features.materials"></p-sortIcon>
                                    </th>
                                    <th style="width: 100px;text-align: center;" pSortableColumn="price">
                                        价格(元)
                                        <p-sortIcon field="price"></p-sortIcon>
                                    </th>
                                    <th style="width: 120px;text-align: center;" pSortableColumn="isTempering">
                                        是否表面处理
                                        <p-sortIcon field="isTempering"></p-sortIcon>
                                    </th>
                                    <th style="width: 120px;text-align: center;" pSortableColumn="safetyStock">
                                        安全库存量
                                        <p-sortIcon field="safetyStock"></p-sortIcon>
                                    </th>
                                </tr>
                            </ng-template>
                            <ng-template pTemplate="body" let-record="$implicit" let-rowIndex="rowIndex">
                                <tr>
                                    <td style="width: 100px"
                                        [hidden]="!isGrantedAny('Pages.StandardPartsManager.CodeBase.Add', 'Pages.StandardPartsManager.CodeBase.Edit', 'Pages.StandardPartsManager.CodeBase.Delete')">
                                        <div class="btn-group dropdown" dropdown container="body">
                                            <button dropdownToggle class="dropdown-toggle btn btn-sm btn-primary">
                                                <i class="fa fa-cog"></i><span class="caret"></span> {{"Actions" | localize}}
                                            </button>
                                            <ul class="dropdown-menu" *dropdownMenu>
                                                <li>
                                                    <a href="javascript:;" *ngIf="'Pages.StandardPartsManager.CodeBase.Edit' | permission"
                                                       (click)="createOrEditCodeBaseModal.show(record)">{{'Edit' | localize}}</a>
                                                </li>
                                                <!--<li>
                                                    <a href="javascript:;" *ngIf="'Pages.Administration.Users.Edit' | permission"
                                                       (click)="logCodeBaseModal.show(record.id)">日志</a>
                                                </li>-->
                                                <li>
                                                    <a href="javascript:;" *ngIf="'Pages.StandardPartsManager.CodeBase.Delete' | permission"
                                                       (click)="deleteCodeBase(record)">{{'Delete' | localize}}</a>
                                                </li>
                                            </ul>
                                        </div>
                                    </td>
                                    <td style="width: 50px;;text-align: center;"  >
                                        <span class="ui-column-title">序号</span>
                                        {{rowIndex + 1}}
                                    </td>
                                    <td style="width: 100px;;text-align: center;" >
                                        <span class="ui-column-title">编码</span>
                                        {{record.serialNumber}}
                                    </td>
                                    <td style="width: 100px;text-align: center;">
                                        <span class="ui-column-title">名称</span>
                                        {{record.features.displayName}}
                                    </td>
                                    <td style="width: 100px;text-align: center;">
                                        <span class="ui-column-title">分类</span>
                                        {{getStandarType(record.standardType)}}
                                    </td>
                                    <td style="width: 100px;text-align: center;">
                                        <span class="ui-column-title">标准</span>
                                        {{record.features.standardNumber}}
                                    </td>
                                    <td style="width: 100px;text-align: center;">
                                        <span class="ui-column-title">规格</span>
                                        {{record.features.specification}}
                                    </td>
                                    <td style="width: 100px;text-align: center;">
                                        <span class="ui-column-title">材料</span>
                                        {{record.features.materials}}
                                    </td>
                                    <td style="width: 120px;;text-align: center;">
                                        <span class="ui-column-title">价格(元)</span>
                                        {{record.price}}
                                    </td>
                                    <td style="width: 120px;;text-align: center;" >
                                        <span class="ui-column-title">是否表面处理</span>
                                        {{ getStandardPartsDetailIsTemperingText(record.isTempering) }}
                                    </td>
                                    <td style="width: 120px;;text-align: center;" >
                                        <span class="ui-column-title">安全库存量</span>
                                        {{record.safetyStock}}
                                    </td>
                                </tr>
                            </ng-template>
                        </p-table>
                        <div class="primeng-no-data" *ngIf="primengTableHelper.totalRecordsCount == 0">
                            {{'NoData' | localize}}
                        </div>
                        <div class="primeng-paging-container">
                            <p-paginator [rows]="primengTableHelper.defaultRecordsCountPerPage"
                                         #paginator
                                         (onPageChange)="getCodeBase($event)"
                                         [totalRecords]="primengTableHelper.totalRecordsCount"
                                         [rowsPerPageOptions]="primengTableHelper.predefinedRecordsCountPerPage">

                            </p-paginator>
                            <span class="total-records-count">
                                {{'TotalRecordsCount' | localize:primengTableHelper.totalRecordsCount}}
                            </span>
                        </div>
                    </div>
                    <!--<Primeng-TurboTable-End>-->
                </div>
            </div>
        </div>
    </div>
    <createOrEditCodeBaseModal #createOrEditCodeBaseModal (modalSave)="getCodeBase()"></createOrEditCodeBaseModal>
    <!--<logCodeBaseModal #logCodeBaseModal></logCodeBaseModal>-->
</div>
